package company.guanglianda;

import java.util.Scanner;

public class GuangLianDa2 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int maxNum = -1, result = 0;
        //数 指针位置
        for (int i = 1; i <= n; i++) {
            int num = sc.nextInt();
            if (num != i && num > maxNum) {
                maxNum = num;
                result = n - i;
            }
        }
        if (maxNum == -1)
            System.out.println(0);
        else
            System.out.println(result);
    }
}
